package MydbQA::Command::Analyze;

use strict;
use warnings;

use base 'MydbQA::Command::Base';
use Carp;

sub run {
      my $self = shift;
      #print "opa\n"; die;
      
      my @links;
      foreach (@{$self->analyze_commands}) {
            push @links , {cmd => lc($_) , name => ucfirst($_)};
            eval {
                  my $class = "MydbQA::Command::$_";
                  eval "use $class";
                  my $cmd = $class->new(%{$self});
                  $cmd->run();
            };
      }
      
      my @input_args = ();
      for (keys %$self) {
            if ($_ !~ /^_/ and $self->{$_} and !ref $self->{$_}) {
                  my %temp = ();
                  $temp{arg_name} = $_;
                  $temp{arg_value} = $self->{$_};
                  push @input_args , \%temp;
            }
      }
      
      my $tmpl = HTML::Template->new( filename => "../share/tmpl/a.html" , die_on_bad_params => 0 );
      $tmpl->param(version => $self->{_version});
      $tmpl->param(links => \@links);
      $tmpl->param(input_args => \@input_args);
      
      my $path = $self->{output};
      
      open (FH , "+>$path/index.html") || die print $!;
            print FH $tmpl->output;
      close FH;
      
      print "Full analyze report created in $path/\n"; 
}

1;
